package cn.com.zetatech.loader.util;

import cn.com.zetatech.loader.resolver.service.CalculatorStrategy;

/**
 * @author jian.chen@zetatech.com.cn
 * @Description TODO
 * @Date 2024/8/27 11:08
 */
public enum Operation implements CalculatorStrategy {
    ADDITION {
        @Override
        public double calculate(double a, double b) {
            return a + b;
        }
    },
    SUBTRACTION {
        @Override
        public double calculate(double a, double b) {
            return a - b;
        }
    },
    MULTIPLICATION {
        @Override
        public double calculate(double a, double b) {
            return a * b;
        }
    },
    DIVISION {
        @Override
        public double calculate(double a, double b) {
            if (b == 0) {
                throw new ArithmeticException("Division by zero is not allowed.");
            }
            return a / b;
        }
    };


    public static void main(String[] args) {
        double a = 10;
        double b = 5;

        // 使用加法策略
        double resultAdd = Operation.ADDITION.calculate(a, b);
        System.out.println("Addition Result: " + resultAdd);

        // 使用减法策略
        double resultSubtract = Operation.SUBTRACTION.calculate(a, b);
        System.out.println("Subtraction Result: " + resultSubtract);

        // 使用乘法策略
        double resultMultiply = Operation.MULTIPLICATION.calculate(a, b);
        System.out.println("Multiplication Result: " + resultMultiply);

        // 使用除法策略
        double resultDivide = Operation.DIVISION.calculate(a, b);
        System.out.println("Division Result: " + resultDivide);
    }
}

